﻿using System.Collections.Generic;
using System.Linq;
namespace Sharp.Platform.Mvc.Bootstrap
{
    public abstract class StyleConfiguration<T> where T : class
    {
        private readonly string _prefix;
        protected T Instance;
        protected string Value;
        private readonly List<string> _styles = new List<string>();

        protected StyleConfiguration(string prefix, T instance)
        {
            _prefix = prefix;
            _styles.Add("");

            Instance = instance;
        }

        public T Default()
        {
            _styles.Add("-default");
            return Instance;
        }

        public T Primary()
        {
            _styles.Add("-primary");
            return Instance;
        }

        public T Success()
        {
            _styles.Add("-success");
            return Instance;
        }

        public T Info()
        {
            _styles.Add("-info");
            return Instance;
        }

        public T Warning()
        {
            _styles.Add("-warning");
            return Instance;
        }

        public T Danger()
        {
            _styles.Add("-danger");
            return Instance;
        }
        public T Block()
        {
            _styles.Add("-block");
            return Instance;
        }
        public T Flat()
        {
            _styles.Add("-flat");
            return Instance;
        }
        #region Overrides of Object

        /// <summary>
        /// 返回表示当前 <see cref="T:System.Object"/> 的 <see cref="T:System.String"/>。
        /// </summary>
        /// <returns>
        /// <see cref="T:System.String"/>，表示当前的 <see cref="T:System.Object"/>。
        /// </returns>
        public override string ToString()
        {
            if (_styles.Count() > 2 && _styles.Count(x => x != "-default" && x != "") > 0)
            {
                _styles.RemoveAll(x => x == "-default");
            }
            var temp = _styles.Distinct().Select(x => _prefix + x).ToList();
            return string.Join(" ", temp);
        }

        #endregion Overrides of Object
    }
}